package logger2.colorer;

import java.awt.Color;
import java.util.EventObject;

import zerdlib.events.MergableEventObject;


public class ColorerEvent extends EventObject implements MergableEventObject {
	private static final long serialVersionUID = 4091028588766319356L;

	public static final int RENAME=1, DEFAULT_COLOR_CHANGE=2, ADD=3, REMOVE=4, DATA_CHANGE=5, MOVE=6, ALL=7;
	
	private int type;
	private String oldName;
	private int index, oldIndex, newIndex;
	private Color oldColor;
	private FCcouple couple;
	
	private ColorerEvent(Colorer source, int type, String oldName, int index, int oldIndex, int newIndex, Color oldColor, FCcouple couple) {
		super(source);
		this.type = type;
		this.oldName = oldName;
		this.index = index;
		this.oldIndex = oldIndex;
		this.newIndex = newIndex;
		this.oldColor = oldColor;
		this.couple = couple;
	}

	@Override
	public boolean merge(EventObject ev) {
		type = ALL;
		return true;
	}
	
	
	public static ColorerEvent renameEvent(Colorer source, String oldName) {
		return new ColorerEvent(source, RENAME, oldName, 0, 0, 0, null, null);
	}
	public static ColorerEvent defaultColorChangeEvent(Colorer source, Color oldColor) {
		return new ColorerEvent(source, DEFAULT_COLOR_CHANGE, null, 0, 0, 0, oldColor, null);
	}
	public static ColorerEvent addEvent(Colorer source, FCcouple newCouple, int index) {
		return new ColorerEvent(source, ADD, null, index, 0, 0, null, newCouple);
	}
	public static ColorerEvent removeEvent(Colorer source, FCcouple oldCouple, int index) {
		return new ColorerEvent(source, REMOVE, null, index, 0, 0, null, oldCouple);
	}
	public static ColorerEvent dataChangeEvent(Colorer source, FCcouple newCouple, int index) {
		return new ColorerEvent(source, DATA_CHANGE, null, index, 0, 0, null, newCouple);
	}
	public static ColorerEvent moveEvent(Colorer source, FCcouple movedCouple, int oldIndex, int newIndex) {
		return new ColorerEvent(source, MOVE, null, 0, oldIndex, newIndex, null, null);
	}

	public int getType() {
		return type;
	}

	public String getOldName() {
		return oldName;
	}

	public int getIndex() {
		return index;
	}

	public int getOldIndex() {
		return oldIndex;
	}

	public int getNewIndex() {
		return newIndex;
	}

	public Color getOldColor() {
		return oldColor;
	}

	public FCcouple getCouple() {
		return couple;
	}
	
	@Override
	public Colorer getSource() {
		// TODO Auto-generated method stub
		return (Colorer) super.getSource();
	}
}
